package com.gt.quality.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * SpringBoot启动完成加载执行
 *
 * @author: makeJava
 * @createTime: 2026-02-26 21:50
 * @since JDK 21 And SpringBoot 3.X
 */
@Component
public class MyApplicationRunning implements ApplicationRunner {

    private static final Logger logger = LoggerFactory.getLogger(MyApplicationRunning.class);


    private Environment environment;

    @Autowired
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }

    @Override
    public void run(ApplicationArguments args) {
        printBaseInfo();
    }

    private static final String APPLICATION_RUNNING_INFO =
            """
                    ----------------------Layui-Vue-Admin管理系统------------------------------------
                        Application is running! Access URL:
                        Local: \thttp://localhost:{}/
                    ----------------------------------------------------------
                    """;

    private static final int DEFAULT_PORT = 8080;

    public void printBaseInfo() {
        String port = environment.getProperty("server.port");
        if (port == null) {
            port = String.valueOf(DEFAULT_PORT);
        }

        if (logger.isInfoEnabled()) {
            logger.info(APPLICATION_RUNNING_INFO, port);
        } else {
            logger.debug("Logger not initialized or info level logging is not enabled.");
        }
    }

}
